﻿using Core.SimpleTemp.Common;
using Core.SimpleTemp.Entitys.Sys;
using Core.SimpleTemp.Repositories.Internal;
using Core.Toolkit.AutoMapperExtend.DataDictionary;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*----------------------------------------------------------------
* 描述 ：
* 作    者 ：Tengsheng Hou
* 更新时间 ：2019/7/22 9:27:25
//----------------------------------------------------------------*/
namespace Core.SimpleTemp.Repositories.Sys
{
    [AutoDi(typeof(IDataDicProvider))]
    [AutoDi(typeof(SysFactoryRepository))]
    public class SysFactoryRepository : IDataDicProvider
    {
        const string DIC_CATEGORY_CODE = "9001";
        const string DIC_CATEGORY_CODE_ALL = "9002";
        CoreDBContext _dbContext;
        public SysFactoryRepository(CoreDBContext dbContext)
        {
            _dbContext = dbContext;
        }

        public async System.Threading.Tasks.Task<List<SysFactory>> GetFactoriesAsync()
        {
            return await _dbContext.SysFactory.ToListAsync();
        }

        public void LoadData(Dictionary<string, string> _dataDic, Dictionary<string, List<DataDicModel>> _dataDicListByCategory)
        {
            var factoryList = _dbContext.SysFactory.ToList();
            #region 9001 不帶总部

            var list = factoryList.Where(f => f.FactoryType != "1").ToList();
            foreach (var item in list)
            {
                _dataDic.TryAdd($"{DIC_CATEGORY_CODE}_{item.Id}", item.FactoryName);
            }
            _dataDicListByCategory.TryAdd(DIC_CATEGORY_CODE, list.Select(sdd => new DataDicModel()
            {
                Category = DIC_CATEGORY_CODE,
                Key = sdd.Id.ToString(),
                Value = sdd.FactoryName
            }).ToList());
            #endregion

            #region 9002 ALL

            
            foreach (var item in factoryList)
            {
                _dataDic.TryAdd($"{DIC_CATEGORY_CODE_ALL}_{item.Id}", item.FactoryName);
            }
            _dataDicListByCategory.TryAdd(DIC_CATEGORY_CODE_ALL, factoryList.Select(sdd => new DataDicModel()
            {
                Category = DIC_CATEGORY_CODE_ALL,
                Key = sdd.Id.ToString(),
                Value = sdd.FactoryName
            }).ToList());
            #endregion


        }
    }
}
